package com.ruoyi.talk.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.talk.domain.GroupRecordChat;
import com.ruoyi.talk.service.IGroupRecordChatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 群组聊天记录Controller
 * 
 * @author HaiWang
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/talk/chat")
public class GroupRecordChatController extends BaseController
{
    @Autowired
    private IGroupRecordChatService groupRecordChatService;

    /**
     * 查询群组聊天记录列表
     */
    @PreAuthorize("@ss.hasPermi('talk:chat:list')")
    @GetMapping("/list")
    public TableDataInfo list(GroupRecordChat groupRecordChat)
    {
        startPage();
        List<GroupRecordChat> list = groupRecordChatService.selectGroupRecordChatList(groupRecordChat);
        return getDataTable(list);
    }

    /**
     * 导出群组聊天记录列表
     */
    @PreAuthorize("@ss.hasPermi('talk:chat:export')")
    @Log(title = "群组聊天记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupRecordChat groupRecordChat)
    {
        List<GroupRecordChat> list = groupRecordChatService.selectGroupRecordChatList(groupRecordChat);
        ExcelUtil<GroupRecordChat> util = new ExcelUtil<GroupRecordChat>(GroupRecordChat.class);
        util.exportExcel(response, list, "群组聊天记录数据");
    }

    /**
     * 获取群组聊天记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('talk:chat:query')")
    @GetMapping(value = "/{groupChatRecordId}")
    public AjaxResult getInfo(@PathVariable("groupChatRecordId") Long groupChatRecordId)
    {
        return success(groupRecordChatService.selectGroupRecordChatByGroupChatRecordId(groupChatRecordId));
    }

    /**
     * 新增群组聊天记录
     */
    @PreAuthorize("@ss.hasPermi('talk:chat:add')")
    @Log(title = "群组聊天记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupRecordChat groupRecordChat)
    {
        return toAjax(groupRecordChatService.insertGroupRecordChat(groupRecordChat));
    }

    /**
     * 修改群组聊天记录
     */
    @PreAuthorize("@ss.hasPermi('talk:chat:edit')")
    @Log(title = "群组聊天记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupRecordChat groupRecordChat)
    {
        return toAjax(groupRecordChatService.updateGroupRecordChat(groupRecordChat));
    }

    /**
     * 删除群组聊天记录
     */
    @PreAuthorize("@ss.hasPermi('talk:chat:remove')")
    @Log(title = "群组聊天记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupChatRecordIds}")
    public AjaxResult remove(@PathVariable Long[] groupChatRecordIds)
    {
        return toAjax(groupRecordChatService.deleteGroupRecordChatByGroupChatRecordIds(groupChatRecordIds));
    }
}
